﻿using Jw.Core;
using Jw.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using Jw.Web.App_Start;

namespace Jw.Web.Areas.Basic.Controllers
{
    public class DwzdController : BaseController
    {
        //
        // GET: /Basic/Dwzd/

        public ActionResult Index()
        {
            var model = new
            {
                dataSource = new
                {
                    
                },
                form = new
                {
                   
                } 
            };
            return View(model);
        }
    }

    public class DwzdApiController : ApiController
    {
        public dynamic Get(RequestWrapper query)
        {
            query.LoadSettingXmlString(@"
            <settings defaultOrderBy='Dwzd_Dwbh DESC'>
            <select>*</select>
                <from>l_Dwzd</from>
                    <where defaultForAll='true' defaultCp='equal' defaultIgnoreEmpty='true' >
                        <field name='Dwzd_Dwbh' cp='like'></field>
                    </where>
            </settings>");
            var service = new Jw.Models.l_DwzdService();
            var pQuery = query.ToParamQuery();
            var result = service.GetDynamicListWithPaging(pQuery);

            return result;
        }


        /// <summary>
        /// 物料类别
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public dynamic GetTypes(RequestWrapper request)
        {
            request.LoadSettingXmlString(@"
            <settings defaultOrderBy='Dwlb_Lbbh'>
               <where defaultIgnoreEmpty='true'>
                    <field name='Dwlb_Lbbh' cp='like'></field>
                </where>
            </settings>
            ");
            var result = new l_DwlbService().GetDynamicList(request.ToParamQuery());
            return result;
        }


        /// <summary>
        /// 得到编号
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public string GetNewCode(string id)
        {
            var service = new l_DwzdService();
            return service.GetNewDwzdCode(id);
        }


        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="data"></param>
        [System.Web.Http.HttpPost]
        public void Edit(dynamic data)
        {
            var listWrapper = RequestWrapper.Instance().LoadSettingXmlString(@"
            <settings>
                <table>l_Dwzd</table>
                <where>
                    <field name='Dwzd_Dwbh' cp='equal'></field>
                </where>
            </settings>");
            var service = new l_DwzdService();
            var result = service.Edit(null, listWrapper, data);
        }



        /// <summary>
        /// 类别-编辑
        /// </summary>
        /// <param name="data"></param>
        [System.Web.Http.HttpPost]
        public void EditType(dynamic data)
        {
            var listWrapper = RequestWrapper.Instance().LoadSettingXmlString(@"
            <settings>
                <table>l_Dwlb</table>
                <where>
                    <field name='Dwlb_Lbbh' cp='equal'></field>
                </where>
            </settings>");
            var service = new l_DwlbService();
            var result = service.Edit(null, listWrapper, data);
        }
    }
}
